package utils

import (
	"github.com/gogf/gf/encoding/gjson"
	"github.com/gogf/gf/frame/g"
)

// @staticmethod
// def push_notify_charge(redis, uid, param1, param2):
// 	item = {'users':[uid],'param1':param1,'param2':param2,'notifi_type':N_CHARGE}
// 	redis.lpush('notification_queue', json.dumps(item))

// 修改用户金额
func PushChangeUserMoney(uid int, money float64, bonusMoney float64) bool {
	jsonstr, _ := gjson.Encode(g.Map{
		"uid":         uid,
		"money":       money,
		"bonus_money": bonusMoney,
	})

	result, err := g.Redis().DoVar("lpush", "user_money_queue", jsonstr)
	if err != nil {
		g.Log("pay").Cat("redis").Info("【redis】推送数据出错:" + string(jsonstr) + "，" + err.Error())
		return false
	}
	if result.Int() == 1 {
		return true
	}
	return false
}

// 推送充值变化
func PushNotify(uids []int, param1 int, param2 string, notifyType int) bool {

	jsonstr, _ := gjson.Encode(g.Map{
		"users":       uids,
		"param1":      param1,
		"param2":      param2,
		"notifi_type": notifyType,
	})

	result, err := g.Redis().DoVar("lpush", "notification_queue", jsonstr)
	if err != nil {
		g.Log("pay").Cat("redis").Info("【redis】推送数据出错:" + string(jsonstr) + "，" + err.Error())
		return false
	}
	if result.Int() == 1 {
		return true
	}
	return false
}
